#!/usr/bin/env bash


#################结束服务####################
THREAD_NAME=$1

APP_HOME=`cd $(dirname $0)/..;pwd`
LOG_DIR="$APP_HOME"/logs
PID_FILE="${LOG_DIR}"/run.pid

if [ ! -f ${PID_FILE} ]; then
	echo "run.pid not exist！！！"
fi


pid=`cat $PID_FILE`


procinfo=`ps -ef|grep -w ${pid}|grep -v grep`
count=0
while [ $count -lt 10 ]; do
	if [ -z "${procinfo}" ]; then
		echo "kill  $pid successful"
		rm -rf ${PID_FILE}
		sleep 1
		break
	fi
	kill $pid

	sleep 1

	procinfo=`ps -ef|grep -w ${THREAD_NAME} | grep -v grep`
	count=`expr $count + 1`
done

ps -ef | grep ${THREAD_NAME} | grep -v grep | awk '{print $2}' |xargs kill -9